home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_proc_mutex.h.z / apr_proc_mutex.h
C/C++ Source or Header  |  2002-07-08  |  7KB  |  177 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_PROC_MUTEX_H
  56. #define APR_PROC_MUTEX_H
  57.  
  58. #include "apr.h"
  59. #include "apr_pools.h"
  60. #include "apr_errno.h"
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif /* __cplusplus */
  65.  
  66. /**
  67.  * @file apr_proc_mutex.h
  68.  * @brief APR Process Locking Routines
  69.  */
  70.  
  71. /**
  72.  * @defgroup APR_ProcMutex Process Locking Routines
  73.  * @ingroup APR
  74.  * @{
  75.  */
  76.  
  77. typedef enum {APR_LOCK_FCNTL, APR_LOCK_FLOCK, APR_LOCK_SYSVSEM,
  78.               APR_LOCK_PROC_PTHREAD, APR_LOCK_POSIXSEM,
  79.               APR_LOCK_DEFAULT} apr_lockmech_e;
  80.  
  81. typedef struct apr_proc_mutex_t apr_proc_mutex_t;
  82.  
  83. /*   Function definitions */
  84.  
  85. /**
  86.  * Create and initialize a mutex that can be used to synchronize processes.
  87.  * @param mutex the memory address where the newly created mutex will be
  88.  *        stored.
  89.  * @param fname A file name to use if the lock mechanism requires one.  This
  90.  *        argument should always be provided.  The lock code itself will
  91.  *        determine if it should be used.
  92.  * @param mech The mechanism to use for the interprocess lock, if any; one of
  93.  * <PRE>
  94.  *            APR_LOCK_FCNTL
  95.  *            APR_LOCK_FLOCK
  96.  *            APR_LOCK_SYSVSEM
  97.  *            APR_LOCK_POSIXSEM
  98.  *            APR_LOCK_PROC_PTHREAD
  99.  *            APR_LOCK_DEFAULT     pick the default mechanism for the platform
  100.  * </PRE>
  101.  * @param pool the pool from which to allocate the mutex.
  102.  * @warning Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
  103.  *          APR_LOCK_foo.  Only APR_LOCK_DEFAULT is portable.
  104.  */
  105. APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
  106.                                                 const char *fname,
  107.                                                 apr_lockmech_e mech,
  108.                                                 apr_pool_t *pool);
  109.  
  110. /**
  111.  * Re-open a mutex in a child process.
  112.  * @param mutex The newly re-opened mutex structure.
  113.  * @param fname A file name to use if the mutex mechanism requires one.  This
  114.  *              argument should always be provided.  The mutex code itself will
  115.  *              determine if it should be used.  This filename should be the 
  116.  *              same one that was passed to apr_proc_mutex_create().
  117.  * @param pool The pool to operate on.
  118.  * @remark This function must be called to maintain portability, even
  119.  *         if the underlying lock mechanism does not require it.
  120.  */
  121. APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
  122.                                                     const char *fname,
  123.                                                     apr_pool_t *pool);
  124.  
  125. /**
  126.  * Acquire the lock for the given mutex. If the mutex is already locked,
  127.  * the current thread will be put to sleep until the lock becomes available.
  128.  * @param mutex the mutex on which to acquire the lock.
  129.  */
  130. APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex);
  131.  
  132. /**
  133.  * Attempt to acquire the lock for the given mutex. If the mutex has already
  134.  * been acquired, the call returns immediately with APR_EBUSY. Note: it
  135.  * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
  136.  * if the return value was APR_EBUSY, for portability reasons.
  137.  * @param mutex the mutex on which to attempt the lock acquiring.
  138.  */
  139. APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex);
  140.  
  141. /**
  142.  * Release the lock for the given mutex.
  143.  * @param mutex the mutex from which to release the lock.
  144.  */
  145. APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex);
  146.  
  147. /**
  148.  * Destroy the mutex and free the memory associated with the lock.
  149.  * @param mutex the mutex to destroy.
  150.  */
  151. APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex);
  152.  
  153. /**
  154.  * Display the name of the mutex, as it relates to the actual method used.
  155.  * This matches the valid options for Apache's AcceptMutex directive
  156.  * @param mutex the name of the mutex
  157.  */
  158. APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex);
  159.  
  160. /**
  161.  * Display the name of the default mutex: APR_LOCK_DEFAULT
  162.  * @param mutex the name of the default mutex
  163.  */
  164. APR_DECLARE(const char *) apr_proc_mutex_defname(void);
  165.  
  166. /**
  167.  * Get the pool used by this proc_mutex.
  168.  * @return apr_pool_t the pool
  169.  */
  170. APR_POOL_DECLARE_ACCESSOR(proc_mutex);
  171.  
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175.  
  176. #endif  /* ! APR_PROC_MUTEX_H */
  177.